<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title><?php echo ($system_name); ?>管理中心 - <?php echo ($page_name); ?></title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="stylesheet" href="/shop/Public/css/amazeui.min.css"/>
    <link rel="stylesheet" href="/shop/Public/css/admin.css"/>
    <link rel="stylesheet" href="/shop/Public/css/validform.css"/>
</head>
<body>
    <div class="admin-content">

        <!--页头-->
        <div class="am-cf am-padding">
            <div class="am-fl am-cf">
                <strong class="am-text-primary am-text-lg">商品管理</strong> / <small><?php echo ($page_name); ?></small>
            </div>
            <div class="am-g">
                <div class="am-u-sm-12 am-u-md-2 am-u-sm-offset-8">
                    <div class="am-btn-toolbar">
                        <div class="am-btn-group am-btn-group-xs">
                            <a href="<?php echo U('goods/goods_list');?>" class="am-btn am-btn-default"><span class="am-icon-list"></span> 商品列表</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <hr/>
        <form method="post" class="am-form am-form-inline" id="goods_form">
        <input type="hidden" name="goods_id"/>
        <div class="am-tabs am-margin" data-am-tabs>
            <ul class="am-tabs-nav am-nav am-nav-tabs">
                <?php if(is_array($form_tab)): $key = 0; $__LIST__ = $form_tab;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$list): $mod = ($key % 2 );++$key; if($key == 1): ?><li class="am-active"><a href="#tab<?php echo ($key); ?>"><?php echo ($list); ?></a></li>
                <?php else: ?>
                <li><a href="#tab<?php echo ($key); ?>"><?php echo ($list); ?></a></li><?php endif; endforeach; endif; else: echo "" ;endif; ?>
            </ul>

            <!--表单项-->
            <div class="am-tabs-bd">
                <div class="am-tab-panel am-fade am-in am-active" id="tab1">
                    <?php if(is_array($base_info)): $i = 0; $__LIST__ = $base_info;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$list): $mod = ($i % 2 );++$i; switch($list["type"]): case "text": switch($list["name"]): case "user_price": ?><div class="am-g am-margin-top-sm">
                                            <div class="am-u-sm-4 am-u-md-3 am-text-right"><?php echo ($list["title"]); ?>：</div>
                                            <div class="am-u-sm-8 am-u-md-3 am-u-end am-form-inline"><?php echo get_user_price_field($list['name']);?></div>
                                        </div><?php break;?>
                                    <?php case "discount_price": ?><div class="am-g am-margin-top-sm">
                                            <div class="am-u-sm-4 am-u-md-3 am-text-right"><?php echo ($list["title"]); ?>：</div>
                                            <div class="am-u-sm-8 am-u-md-6 am-u-end"><?php echo get_discount_price_field($goods_id);?></div>
                                        </div><?php break;?>
                                    <?php case "promotion_price": ?><div class="am-g am-margin-top-sm">
                                            <div class="am-u-sm-4 am-u-md-3 am-text-right">
                                                <input type="checkbox" name="is_promoted" id="is_promoted" value="1"/> <?php echo ($list["title"]); ?>：
                                            </div>
                                            <div class="am-u-sm-8 am-u-md-3 am-u-end">
                                                <input type="<?php echo ($list["type"]); ?>" name="<?php echo ($list["name"]); ?>" id="<?php echo ($list["name"]); ?>" nullmsg="<?php echo ($list["nullmsg"]); ?>" disabled/>
                                            </div>
                                        </div><?php break;?>
                                    <?php default: ?>
                                    <div class="am-g am-margin-top-sm">
                                        <div class="am-u-sm-4 am-u-md-3 am-text-right"><?php echo ($list["title"]); ?>：</div>
                                        <div class="am-u-sm-8 am-u-md-3">
                                            <input type="<?php echo ($list["type"]); ?>" name="<?php echo ($list["name"]); ?>" id="<?php echo ($list["name"]); ?>" value="<?php echo get_goods_info($goods_id,$list['name']);?>" datatype="<?php echo ($list["data_type"]); ?>" nullmsg="<?php echo ($list["nullmsg"]); ?>" ignore="<?php echo ($list["ignore"]); ?>"/>
                                        </div>
                                        <div class="am-hide-sm-only am-u-md-6">
                                            <?php if(!empty($list["is_must"])): ?><span class="am-text-danger am-text-xs">*必填</span><?php endif; ?>
                                            <?php switch($list["name"]): case "goods_sn": ?><span class="am-link-muted am-text-xs">如果您不输入商品货号，系统将自动生成一个唯一的货号。</span><?php break;?>
                                                <?php case "give_integral": ?><span class="am-link-muted am-text-xs">购买该商品时赠送消费积分数</span><?php break;?>
                                                <?php case "rank_integral": ?><span class="am-link-muted am-text-xs">购买该商品时赠送等级积分数</span><?php break;?>
                                                <?php case "bought_integral": ?><span class="am-link-muted am-text-xs">(此处需填写金额)购买该商品时最多可以使用积分的金额</span><?php break; endswitch;?>
                                        </div>
                                        </div><?php endswitch; break;?>
                            <?php case "select": ?><div class="am-g am-margin-top-sm">
                                    <div class="am-u-sm-4 am-u-md-3 am-text-right"><?php echo ($list["title"]); ?>：</div>
                                    <div class="am-u-sm-8 am-u-md-3">
                                        <select name="<?php echo ($list["name"]); ?>" id="<?php echo ($list["name"]); ?>" datatype="<?php echo ($list["data_type"]); ?>"  nullmsg="<?php echo ($list["nullmsg"]); ?>" ignore="<?php echo ($list["ignore"]); ?>">
                                            <option value="">请选择...</option>
                                            <?php if($list['name'] == 'goods_category'): if(is_array($goods_category)): $i = 0; $__LIST__ = $goods_category;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><option value="<?php echo ($vo["category_id"]); ?>"><?php echo ($vo["category_name"]); ?></option><?php endforeach; endif; else: echo "" ;endif; endif; ?>
                                        </select>
                                    </div>
                                    <div class="am-hide-sm-only am-u-md-6">
                                        <?php switch($list["name"]): case "goods_category": ?><button type="button" class="am-btn am-btn-secondary" style="margin-right:10px;" onclick="add_category();">添加分类</button><?php break;?>
                                            <?php case "goods_brand": ?><button type="button" class="am-btn am-btn-secondary" style="margin-right:10px;" onclick="add_brand();">添加品牌</button><?php break; endswitch;?>
                                        <?php if(!empty($list["is_must"])): ?><span class="am-text-danger am-text-xs"> * 必填</span><?php endif; ?>
                                    </div>
                                </div><?php break;?>
                            <?php case "hidden_select": ?><div class="am-g am-margin-top-sm">
                                    <div class="am-u-sm-4 am-u-md-3 am-text-right"><?php echo ($list["title"]); ?>：</div>
                                    <div style="display: none;">
                                        <select name="<?php echo ($list["name"]); ?>" id="<?php echo ($list["name"]); ?>">
                                            <option value="0">请选择...</option>
                                        </select>
                                    </div>
                                    <div class="am-hide-sm-only am-u-md-6">
                                        <button type="button" class="am-btn am-btn-secondary" onclick="add_extend_category(this);">添加</button>
                                        <button type="button" class="am-btn am-btn-secondary" style="display: none" onclick="cancle_extend_category(this);">取消</button>
                                    </div>
                                </div><?php break;?>
                            <?php case "date": ?><div class="am-g am-margin-top-sm">
                                    <div class="am-u-sm-4 am-u-md-3 am-text-right"><?php echo ($list["title"]); ?>：</div>
                                    <div class="am-u-sm-8 am-u-md-9 am-form-inline">
                                        <div class="am-form-group am-form-icon">
                                            <i class="am-icon-calendar"></i>
                                            <input type="text" class="am-form-field" name="start_time" id="start_time" disabled>
                                        </div>
                                        <div class="am-form-group am-form-icon">
                                            <i class="am-icon-calendar"></i>
                                            <input type="text" class="am-form-field" name="end_time" id="end_time" disabled>
                                        </div>
                                    </div>
                                </div><?php break;?>
                            <?php case "upload": ?><div class="am-g am-margin-top-sm">
                                    <div class="am-u-sm-4 am-u-md-3 am-text-right"><?php echo ($list["title"]); ?>：</div>
                                    <div class="am-u-sm-8 am-u-md-3 am-u-end">
                                        <div class="am-form-group am-form-file">
                                            <button type="button" class="am-btn am-btn-secondary am-btn-sm">
                                                <i class="am-icon-cloud-upload"></i> 选择要上传的文件</button>
                                            <input id="goods_img" type="file" multiple>
                                        </div>
                                        <div id="file-list"></div>
                                    </div>
                                </div><?php break; endswitch; endforeach; endif; else: echo "" ;endif; ?>
                </div>
                <div class="am-tab-panel am-fade" id="tab2">
                    <script id="container" name="content" type="text/plain"></script>
                </div>
                <div class="am-tab-panel am-fade" id="tab3"></div>
                <div class="am-tab-panel am-fade" id="tab4">
                    <?php if(is_array($other_info)): $i = 0; $__LIST__ = $other_info;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$list): $mod = ($i % 2 );++$i;?><div class="am-g am-margin-top-sm">
                            <div class="am-u-sm-4 am-u-md-3 am-text-right"><?php echo ($list["title"]); ?>：</div>
                            <?php switch($list["type"]): case "text": ?><div class="am-u-sm-8 am-u-md-3">
                                        <input type="<?php echo ($list["type"]); ?>" name="<?php echo ($list["name"]); ?>" id="<?php echo ($list["name"]); ?>"/>
                                    </div>
                                    <div class="am-hide-sm-only am-u-md-6"></div><?php break;?>
                                <?php case "checkbox": ?><div class="am-u-sm-8 am-u-md-6 am-u-end">
                                        <div class="am-btn-group" data-am-button="">
                                        <?php if($list["name"] == 'goods_recommend_attr'): if(is_array($recommend_attr)): $key = 0; $__LIST__ = $recommend_attr;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($key % 2 );++$key; if($key < 4): ?><label class="am-btn am-btn-default am-btn-xs"><input type="checkbox"><?php echo ($vo); ?></label><?php endif; endforeach; endif; else: echo "" ;endif; endif; ?>
                                        </div>
                                    </div><?php break;?>
                                <?php case "radio": ?><div class="am-u-sm-8 am-u-md-6 am-u-end">
                                        <div class="am-btn-group" data-am-button="">
                                        <?php if($list["name"] == 'is_on_sale'): if(is_array($is_on_sale)): $key = 0; $__LIST__ = $is_on_sale;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($key % 2 );++$key;?><label class="am-btn am-btn-default am-btn-xs"><input type="radio" name="is_on_sale"><?php echo ($vo); ?></label><?php endforeach; endif; else: echo "" ;endif; endif; ?>
                                        <?php if($list["name"] == 'is_shipping_free'): ?><label class="am-btn am-btn-default am-btn-xs"><input type="radio" name="is_shipping_free">是</label>
                                            <label class="am-btn am-btn-default am-btn-xs"><input type="radio" name="is_shipping_free">否</label><?php endif; ?>
                                        </div>
                                    </div><?php break;?>
                                <?php case "textarea": ?><div class="am-u-sm-8 am-u-md-6 am-u-end">
                                        <textarea name="<?php echo ($list["name"]); ?>" id="<?php echo ($list["id"]); ?>" row="10"></textarea>
                                    </div><?php break; endswitch;?>
                        </div><?php endforeach; endif; else: echo "" ;endif; ?>
                </div>
                <div class="am-tab-panel am-fade" id="tab5"></div>
            </div>

        </div>

        <div class="am-margin">
            <button type="button" class="am-btn am-btn-primary am-btn-xs" id="btn_sub">确定</button>
            <button type="button" class="am-btn am-btn-primary am-btn-xs">重置</button>
        </div>
        </form>
    </div>
</body>
<script type="text/javascript" src="/shop/Public/js/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="/shop/Public/js/amazeui.min.js"></script>
<script type="text/javascript" src="/shop/Public/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="/shop/Public/js/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" src="/shop/Public/js/Validform/Validform_v5.3.2.js"></script>
<script type="text/javascript" src="/shop/Public/js/layer/layer.js"></script>
<script type="text/javascript">
var ROOT_PATH = '/shop/admin.php';
$(function() {
    $('#goods_form').Validform({
        btnSubmit:"#btn_sub",
        tiptype:function(msg,o){
            if(o.type == 3){
                alert(msg);
                o.obj.addClass('am-field-error');
            }else{
                o.obj.removeClass('am-field-error');
            }
        },
        showAllError:true
    })

    //上传图片后显示文件名称
    $('#goods_img').on('change', function() {
        var fileNames = '';
        $.each(this.files, function() {
            fileNames += '<span class="am-badge">' + this.name + '</span> ';
        });
        $('#file-list').html(fileNames);
    });

    //选择促销后，促销价格，促销时间可填
    $('#is_promoted').click(function(){
        if($(this).is(':checked')){
            $('input:disabled').removeAttr('disabled');
            $('#promotion_price').attr('datatype','n');
            $('#start_time').attr('datatype','*');
            $('#end_time').attr('datatype','*');
        }else{
            $('#promotion_price').attr('disabled','disabled');
            $('#start_time').attr('disabled','disabled');
            $('#end_time').attr('disabled','disabled');
            $('#promotion_price').attr('ignore','ignore');
            $('#start_time').attr('ignore','ignore');
            $('#end_time').attr('ignore','ignore');
        }

    });

    //商品详细信息-编辑器
    var ue = UE.getEditor('container',{
        serverUrl:ROOT_PATH + '/admin/upload_file'
    });
});

function add_price_input(obj){
    var html ='<div>' +
            '<a href="javascript:;" onclick="add_price_input(this)">[+]</a>' +
            '<span class="am-text-xs">优惠数量</span>' +
            '<input type="text" name="discount_amount[]" class="discount_amount" style="display:inline-block;width:30%;margin:0 10px;">' +
            '<span class="am-text-xs">优惠价格</span>' +
            '<input type="text" name="discount_price[]" class="discount_price" style="display:inline-block;width:30%;margin-left:10px;">' +
            '</div>';
    var discount_amount = $(obj).parent().find('.discount_amount').val();
    var discount_price  = $(obj).parent().find('.discount_price').val();
    if(!discount_amount){
        alert('请输入优惠数量');
        return false;
    }
    if(!discount_price){
        alert('请输入优惠价格');
        return false;
    }
    $(obj).parent().append(html);
}

function add_category(){
    layer.open({
        type:2,
        title:'添加商品分类',
        area:['300px','200px'],
        content:'category_info?type=ajax'
    })
}

function add_brand(){
    layer.open({
        type:2,
        title:'添加商品品牌',
        area:['300px','200px'],
        content:'brand_info?type=ajax'
    })
}

function add_extend_category(obj){
    $(obj).parent().prev().addClass('am-u-sm-8 am-u-md-3');
    $(obj).parent().prev().show();
    $(obj).hide();
    $(obj).next().show();
}

function cancle_extend_category(obj){
    $(obj).parent().prev().removeClass('am-u-sm-8 am-u-md-3');
    $(obj).parent().prev().hide();
    $(obj).hide();
    $(obj).prev().show();
}
</script>
</html>